const http = require('http')
const fs = require('fs')
const server = http.createServer((request, respone) => {
    let { pathname } = new URL(request.url, 'http://192.168.12.56:9999')

    if (pathname = '/') {
        pathname = '/index.html'
    }

    const filePath = __dirname + pathname
    console.log(filePath)
    fs.readFile(filePath, (error, data) => {
        if (error) {
            respone.end('<h1>404 Not Found</h1>')
        } else {
            respone.end(data)
        }
    })
})


server.listen(9999, () => {
    console.log('服务在9999端口上运行')
})